package com.gilgamesh.mall.product.controller;

import com.gilgamesh.mall.product.service.ProductDetailService;
import com.gilgamesh.mall.sdk.bean.product.ProductDetailEntity;
import com.gilgamesh.mall.sdk.dto.ResponseDTO;
import com.gilgamesh.mall.sdk.dto.product.ProductDetailDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * @author yanm
 * @date 2021/1/21 15:37
 **/
@RestController
@RequestMapping("api/pdt")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ProductDetailController {

    private final ProductDetailService productDetailService;


    @PostMapping("addPdd")
    public ResponseDTO<Integer> addProductDetail(@RequestBody ProductDetailEntity entity){
        System.out.println("api/pdt/addPdd接口入参 = "+entity.toString());
        return productDetailService.add(entity);
    }

    @PostMapping("listPdd")
    public ResponseDTO<List<ProductDetailDTO>> listPdd(@RequestBody ProductDetailEntity entity){
        System.out.println("api/pdt/listPdd接口入参 = "+entity.toString());
        return productDetailService.listProductDetail(entity);
    }

    @PostMapping("addPDD")
    public ResponseDTO<Integer> addProductDetail(@RequestParam(value = "id",required = false) Long id,
                                                 @RequestParam(value = "title",required = false) String title,
                                                 @RequestParam(value = "showTitle",required = false) String showTitle,
                                                 @RequestParam(value = "productCode",required = false) String productCode,
                                                 @RequestParam(value = "shoppingCartDescription",required = false) String shoppingCartDescription,
                                                 @RequestParam(value = "originalPrice",required = false) BigDecimal originalPrice,
                                                 @RequestParam(value = "currentPrice",required = false) BigDecimal currentPrice){
        ProductDetailEntity entity = new ProductDetailEntity();
        entity.setProductCode(productCode);
        entity.setCurrentPrice(currentPrice);
        entity.setOriginalPrice(originalPrice);
        entity.setTitle(title);
        entity.setCreateTime(new Date());
        entity.setShowTitle(showTitle);
        entity.setShoppingCartDescription(shoppingCartDescription);
        System.out.println("api/pdt/addPdd接口入参 = "+entity.toString());
        return productDetailService.add(entity);
    }


    @PostMapping("listPDD")
    public ResponseDTO<List<ProductDetailDTO>> listPdd(@RequestParam(value = "id",required = false) Long id,
                                                       @RequestParam(value = "title",required = false) String title,
                                                       @RequestParam(value = "showTitle",required = false) String showTitle,
                                                       @RequestParam(value = "productCode",required = false) String productCode,
                                                       @RequestParam(value = "shoppingCartDescription",required = false) String shoppingCartDescription,
                                                       @RequestParam(value = "originalPrice",required = false) BigDecimal originalPrice,
                                                       @RequestParam(value = "currentPrice",required = false) BigDecimal currentPrice,
                                                       @RequestParam(value = "skuCode",required = false) String skuCode){
        ProductDetailEntity entity = new ProductDetailEntity();
        entity.setProductCode(productCode);
        entity.setCurrentPrice(currentPrice);
        entity.setOriginalPrice(originalPrice);
        entity.setTitle(title);
        entity.setShowTitle(showTitle);
        entity.setShoppingCartDescription(shoppingCartDescription);
        entity.setSkuCode(skuCode);
        System.out.println("api/pdt/listPdd接口入参 = "+entity.toString());
        return productDetailService.listProductDetail(entity);
    }


}
